#include <iostream>
#include <fstream>
#include <boost/program_options.hpp>

//to compile:  g++ -lboost_program_options-mt po.cpp

typedef std::vector<std::string> svector;

std::ostream&
operator<< (std::ostream& os, const svector& sv)
{
  for (svector::const_iterator it = sv.begin(); it != sv.end(); ++it)
    {
      os << *it << "... ";
    }
  
  return os;
}

int main()
{
  boost::program_options::options_description config("Configuration");
  boost::program_options::options_description config2("Detail Configuration");
  svector c1;
  svector m12;

  std::string sig1 = "Signature.C1";
  std::string match12 = "C1->C2.match";

  config.add_options()
    (sig1.c_str(), boost::program_options::value< svector >(&c1), "C1 signature");

  boost::program_options::variables_map vm;
  boost::program_options::variables_map vm2;

  std::ifstream ifs("input.mm");
  if (!ifs)
    {
      std::cout << "File input.mm not found!" << std::endl;
      return 0;
    }
  else
    {
      boost::program_options::store(boost::program_options::parse_config_file(ifs, config, true), vm);
      boost::program_options::notify(vm);

      std::cout << "C1:  " << c1 << std::endl;

      // if we want to read the file again, then close and reopen it.
      ifs.close();

      ifs.open("input.mm");

      config.add_options()
	(match12.c_str(), boost::program_options::value< svector >(&m12), "Match C1 to C2");
  
      boost::program_options::store(boost::program_options::parse_config_file(ifs, config, true), vm);
      boost::program_options::notify(vm);
      
      std::cout << "C1:  " << c1 << std::endl;
      std::cout << "M12: " << m12 << std::endl;
    }
}
